package model.admin;

import com.opensymphony.xwork2.ActionSupport;
import java.util.*;
import java.io.File;
import java.sql.*;

import javax.servlet.http.HttpSession;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;

import vo.*;
import vo.mixed.*;
//import model.admin.*;
import myutil.*;

public class SendMessage_SpecializationMo extends ActionSupport {
	int latest_document_id = 0;
	ArrayList<String> receiver_ids = new ArrayList<String>();
	int latest_message_id = 0;
	ResultSet rs;

	public void updatemessage(int[] department_id, String individual_students,
			String subject, String body, File attached_file, String file_name) {

		// TODO Auto-generated method stub
		try {

			Connect c = new Connect();
			if (department_id != null) 
			{
				
				for (int single_department_id : department_id) 
				{
					rs = c.getResult("select * from student_details sd,student_batch sb,degree_department dd,department_details dde where sb.student_id=sd.student_id and sb.degree_department_id=dd.degree_department_id and dd.department_id=dde.department_id and dde.department_id='"+ single_department_id + "'");
					while (rs.next()) 
					{
						// StudentDetailsVo single_object=new
						// StudentDetailsVo();
						receiver_ids.add(rs.getString("email_id"));
						// students_list.add(single_object);

					}
				}
			}
           System.out.println(receiver_ids.size()+"here");
			// System.out.println(individual_students.length());
			if (individual_students != null) {
				String[] individual_students__emails_seperated = individual_students
						.split(";");
				for (String single : individual_students__emails_seperated) 
				{
					rs = c.getResult("select * from student_details where email_id='"
							+ single + "'");
					while (rs.next()) 
					{
						System.out.println("here");
						receiver_ids.add(rs.getString("email_id"));

					}
				}
			}
			// System.out.println(receiver_ids);

			new Common_Message().update_message_table(receiver_ids, body,subject, attached_file, file_name);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
